import Service from "./Service";
import Message from "../message/Message";
import LocalServer from "../server/LocalServer";
import ServerFactory from "../server/ServerFactoty";

export default class LocalService extends Service {



    protected server: LocalServer;


    connect(url:string,port?:number){
        super.connect(url,port);
        this.server = ServerFactory.get(this.url);
        this.onOpen();
        cc.log(' Local servic connect ')
    }

    sendData(message: Message){
        if(this.server){
            let data = this.server.action(message);
            if(data){
                this.onData(data,message.getProtoID());
            }else{
                this.onError({message:' protoID  is not exist '+message.getProtoID()})
            }
        }else{
            this.onError({message:' server is null '})
        }
    }


}
